package net.lzzy.tapDemo;
import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;

import java.util.List;

public class IndexRecordsTest2 {
    public static void main(String[] args) {
        SparkConf conf = new SparkConf().setAppName("IndexRecordsTest").setMaster("local");
        JavaSparkContext jsc = new JavaSparkContext(conf);
        JavaRDD<String> javaRDD = jsc.textFile("src\\records.txt");
        JavaRDD<String> javaRDD1 = jsc.textFile("src\\recordsCityB.txt");

        JavaRDD<String> map1 = javaRDD.map(v1 -> {
                String[] rs = v1.split("\t");
                return rs[2] + "\t" + rs[3];
        });

        JavaRDD<String> map2 = javaRDD1.map(v1 -> {
                String[] rs = v1.split("\t");
                return rs[2] + "\t" + rs[3];
        });
        JavaRDD<String> intersection = map1.intersection(map2).filter(v1 -> {
                return "AK0803".equals(v1.split("\t")[0]);
        });

        List<String> collect = intersection.collect();
        for (String s : collect) {
            System.out.println(s.split("\t")[1]);
        }
    }
}
